﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using FI.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace FI.Core
{
    /// <summary>
    /// This class defines some exteniosn methods against <see cref="AuditableStatefulSet&lt;T&gt;"/>
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Stateful")]
    public static class AuditableStatefulSetExtensions
    {
        /// <summary>
        /// Extract the data entries whose state is not UnChanged.
        /// </summary>
        /// <typeparam name="T">The data entry type.</typeparam>
        /// <param name="auditableEntries">The auditable entries.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The data entries whose state is not UnChanged.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static IEnumerable<Auditable<T>> GetChanges<T>(this AuditableStatefulSet<T> auditableEntries, Predicate<Auditable<T>> predicate = null) where T: StatefulEntry
        {
            Guard.ArgumentNotNull(auditableEntries, "auditableEntries");
            predicate = predicate ?? (auditable => true);
            return (from auditable in auditableEntries
                    where auditable.Entry.State != EntryState.Unchanged && predicate(auditable)
                    select auditable).ToArray();
        }
    }
}